package com.artisan.admin;

import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/*
 * 访问路径: http://localhost:8080/swagger-ui.html#/
 */
public class SwaggerConfiguration {
    @Bean
    public Docket createRestApi()  {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.prprpr.blog"))  // api接口包扫描路径
                // .paths(regex("/restApi.*"))  //只对restApi路径下面的所有连接请求
                .paths(PathSelectors.any())  // 可以根据url路径设置哪些请求加入文档，忽略哪些请求
                .build();
        // return Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation::class.java)).build();
    }

    private ApiInfo apiInfo()  {
        return new ApiInfoBuilder()
                .title("springboot利用swagger构建api文档")  // 设置文档的标题
                .description("简单优雅的restfun风格")  // 设置文档的描述->1.Overview
                .termsOfServiceUrl("http://www.baidu.com")  // 设置文档的License信息->1.3 License information
                .version("1.0")  // 设置文档的版本信息-> 1.1 Version information
                .build();
    }
}
